package com.noble.meether.chat.ui.agora.util;

import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.meether.chat.ui.agora.dialog.listener.GiftSendListener;

/**
 * 音视频辅助工具类
 */
public class RtcUtil {
    private volatile static RtcUtil mInstance;

    public static RtcUtil getInstance() {
        if (mInstance == null) {
            synchronized (RtcUtil.class) {
                if (mInstance == null) {
                    mInstance = new RtcUtil();
                }
            }
        }
        return mInstance;
    }

    // ======================== 聊天同步问题 ===========================
    /**
     * 是否已经收到对方挂断消息
     */
    private boolean isReceiveReject = false;

    public void validChat(long whisperID) {
        long configID = ModuleMgr.getRtcEnginMgr().getEngineConfig().mOtherId;
        if (configID == whisperID) {
            isReceiveReject = true;
            return;
        }
        resetReceiveReject();
    }

    public boolean isReceiveReject() {
        return isReceiveReject;
    }

    public void resetReceiveReject() {
        isReceiveReject = false;
    }

    /**
     * 是否已经主动挂断
     */
    private boolean isHandleUp = false;

    public void setHandleUp() {
        isHandleUp = true;
    }

    public boolean isHandleUp() {
        return isHandleUp;
    }

    public void resetHandleUp() {
        isHandleUp = false;
    }

    /**
     * 女方：是否已经收到过男性取消群发消息
     */
    private boolean isCancelRob = false;

    public void setCancelRob() {
        isCancelRob = true;
    }

    public boolean isCancelRob() {
        return isCancelRob;
    }

    public void resetCancelRob() {
        isCancelRob = false;
    }

    /**
     * 音视频聊天中，收到 2107 / 2108 的挂断消息(接通后快速挂断)
     */
    private boolean isHangUp = false;

    public void setHangUp() {
        isHangUp = true;
    }

    public boolean isHangUp() {
        return isHangUp;
    }

    public void resetHangUp() {
        isHangUp = false;
    }

    public void resetSynchStatus() {
        resetHandleUp();
        resetReceiveReject();
        resetCancelRob();
        resetHangUp();
    }

    // ============== 接收礼物消息回调 ============================
    private static GiftSendListener giftSendListener;

    public GiftSendListener getGiftSendListener() {
        return giftSendListener;
    }

    public void setGiftSendListener(GiftSendListener giftSendListener) {
        RtcUtil.giftSendListener = giftSendListener;
    }
}
